<?php
// application/forms/Article.php

/**
 * This is the guestbook form.  It is in its own directory in the application 
 * structure because it represents a "composite asset" in your application.  By 
 * "composite", it is meant that the form encompasses several aspects of the 
 * application: it handles part of the display logic (view), it also handles 
 * validation and filtering (controller and model).  
 */
class Form_Search extends Zend_Form
{

    protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );
    public function cluBuild($params)
    {
        // set the method for the display form to POST
        $this->setMethod('POST');
        $this->setAction('/en/block/index/search');
		$intValidator = new Zend_Validate_Int();
        //Module
        //config by modules
        $moduleList = Zend_Registry::get('configuration')->modules;
     	$modules = new Zend_Form_Element_MultiCheckbox('modules',  
                             array('disableLoadDefaultDecorators' => true));
        $modules->addMultiOption('all','All');
        foreach ($moduleList as $module=>$actionList)
        {
        	//TODO: for now , just set to module level
	        $modules->addMultiOption($module,$module);
        }
        $modules->addDecorators($this->_noDecorator);
        $this->addElement($modules);
        
        //language
 		$language = new Zend_Form_Element_MultiCheckbox('languages',  
                         array('disableLoadDefaultDecorators' => true)); 
        $language->addMultiOption('all',__('All'))
        		->addMultiOption('vi',__('Vietnamese'))
               ->addMultiOption('en',__('English'))
               ->addMultiOption('cn',__('Chinese'))
               ->addMultiOption('jp',__('Japanese'))
               ->addDecorators($this->_noDecorator);
        $this->addElement($language);
        /*
        //Applicable to which language
 		$theme = new Zend_Form_Element_MultiCheckbox('themes',  
                         array('disableLoadDefaultDecorators' => true));
        $theme->addMultiOption('all',__('All'));
        
        foreach (explode (' ',Zend_Registry::get('configuration')->themes) as $v)
	        $theme->addMultiOption($v, $v);
        $theme->addDecorators($this->_noDecorator);
        $this->addElement($theme);
        */
		// id
        $blockId = new Zend_Form_Element_Text('id', 
                         array('disableLoadDefaultDecorators' => true,
                               'class' => 'inputText'));
		$blockId->addValidator($intValidator)
				 ->addDecorators($this->_noDecorator);
		$this->addElement($blockId);
        
        //block name
        $blockName = new Zend_Form_Element_Text('name', 
                         array('disableLoadDefaultDecorators' => true,
                               'class' => 'inputText'));
		$blockName->addValidator($intValidator)
				 ->addDecorators($this->_noDecorator);
		$this->addElement($blockName);
		
		//roles
        $db = Zend_Db_Table::getDefaultAdapter();
		$sql = "SELECT * FROM permissions";
		$permissions = $db->fetchAll($sql);
		$roles = new Zend_Form_Element_MultiCheckbox('roles',  
                             array('disableLoadDefaultDecorators' => true));
                             
		$roles->addMultiOption(0,__('Anonymous'));                             
		foreach ($permissions as $p)                             
	            $roles->addMultiOption($p['rid'],__($p['rname']));
        $roles->addDecorators($this->_noDecorator);
        $this->addElement($roles);
		
		//html or PHP text
        $positions = new Zend_Form_Element_Checkbox('positions', 
                         array('disableLoadDefaultDecorators' => true));
		$positions->setLabel('positions')
		      	  ->setChecked(false)
		      	  ->setValue(false);
        $positions->addDecorators($this->_noDecorator); 
        $this->addElement($positions);
        
        //themes
        $themes = new Zend_Form_Element_MultiCheckbox('themes',array('disableLoadDefaultDecorators' => true));
        $themes->addMultiOption('all',__('All'));
        foreach (explode (' ',Zend_Registry::get('configuration')->themes) as $v)
	        $themes->addMultiOption($v, $v);
        $themes->addDecorators($this->_noDecorator);
        $this->addElement($themes);
        
        //template
        $template = new Zend_Form_Element_MultiCheckbox('template',array('disableLoadDefaultDecorators' => true));
        $template->addMultiOption('all',__('All'));
        foreach (explode(' ', Zend_Registry::get('configuration')->templates) as $k => $v)
	        $template->addMultiOption($v, $v);
        $template->addDecorators($this->_noDecorator);
        $this->addElement($template);
        
        //region
        $region = new Zend_Form_Element_Select('region',array('disableLoadDefaultDecorators' => true));
        $region->addMultiOption('all',__('All'));
        $region->addMultiOption('1', __('1'))
        	   ->addMultiOption('2', __('2'))
        	   ->addMultiOption('3', __('3'))
        	   ->addMultiOption('4', __('4'))
        	   ->addMultiOption('5', __('5'));
        $region->addDecorators($this->_noDecorator);
        $this->addElement($region);
        
        //weight
        $weight = new Zend_Form_Element_Select('weight', 
                         array('disableLoadDefaultDecorators' => true));
		$weight->addMultiOption('all', __('Select'))
			   ->addMultiOption('1', __('1'))
        	   ->addMultiOption('2', __('2'))
        	   ->addMultiOption('3', __('3'))
        	   ->addMultiOption('4', __('4'))
        	   ->addMultiOption('5', __('5'));
        $weight->addDecorators($this->_noDecorator); 
        $this->addElement($weight);
        
        // add the submit button
        $submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                               'label' => __('Search') ));
        $submit->addDecorators($this->_noDecorator);
        $this->addElement($submit);
    }
    
    public function populateForm($data)
    {
		$this->populate($data);
    }
}
?>